package com.umeox.zikrringtest.single_test.gsensor

import android.content.Context
import android.text.TextUtils
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import com.umeox.zikrringtest.R
import com.umeox.base.AbsDialog

class InputDialog(val context: Context) : com.umeox.base.AbsDialog(context) {
    override fun getLayoutId(): Int {
        return R.layout.dialog_input
    }

    override fun getBgOutSizeAlpha(): Float {
        return 0.7f
    }

    override fun getCancelable(): Boolean {
        return false
    }

    fun setOnConfirmListener(confirm: (name: String) -> Unit) {
        dialogView.findViewById<TextView>(R.id.btClose).setOnClickListener {
            dismissDialog()
        }

        dialogView.findViewById<TextView>(R.id.btSave).setOnClickListener {
            val name = dialogView.findViewById<EditText>(R.id.etName).text.toString()
            if (TextUtils.isEmpty(name)) {
                Toast.makeText(context, "请输入文件名", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }
            dismissDialog()
            confirm(name)
        }
    }

}